package com.kabigon.tiny.test.bean.entity;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.util.LinkedHashMap;
import java.util.Map;

@Data
public class Example {

    @JsonIgnore
    private String sex;
    @JsonIgnore
    private Map<String, Object> additionalProperties = new LinkedHashMap<>();

    @JsonIgnore
    @JsonAnyGetter
    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    @JsonAnySetter
    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }

    // Other properties and methods...

    public static void main(String[] args) throws Exception {
        String jsonString = "{\"name\": \"John\", \"age\": 30, \"extraProperty\": \"extraValue\"}";
        //Example example = new Example();
        //example.setAdditionalProperty("extraProperty", "extraValue");


        ObjectMapper objectMapper = new ObjectMapper();
        Example example = objectMapper.readValue(jsonString, Example.class);
        example.setAdditionalProperty("address", "beijin");
        example.setSex("nan");
        String json = objectMapper.writeValueAsString(example);

        System.out.println(json);  // The JSON output won't include "additionalProperties".
    }
}